package com.usian.service.impl;

import com.usian.mapper.CommodityMapper;
import com.usian.pojo.Commodity;
import com.usian.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommodityServiceImpl implements CommodityService {

    @Autowired
    private CommodityMapper commodityMapper;

    @Override
    public List<Commodity> findAll() {
        return commodityMapper.selectAll();
    }

    @Override
    public void add(Commodity commodity) {
        commodity.setCreatedTime(new Date());
        commodity.setPutaway(0);
        commodityMapper.insertSelective(commodity);
    }

    @Override
    public void del(Integer pid) {
        commodityMapper.deleteByPrimaryKey(pid);
    }

    @Override
    public void updateById(Commodity commodity) {
        commodityMapper.updateByPrimaryKeySelective(commodity);
    }
}
